window.addEventListener('load', function () {
  // 手机号验证
  var tel = this.document.querySelector('#tel');
  var telReg = /^1[34578]\d{9}$/;
  regexp(tel, telReg);

  // QQ验证（从10000开始）
  var qq = this.document.querySelector('#qq');
  var qqReg = /^[1-9]\d{4,}$/;
  regexp(qq, qqReg);

  // 昵称验证（中文）
  var nick = this.document.querySelector('#nick');
  var nickReg = /^[\u4e00-\u9fa5]{2,8}$/;
  regexp(nick, nickReg);

  // 短信验证码
  var msg = this.document.querySelector('#msg');
  var msgReg = /^\d{6}$/;
  regexp(msg, msgReg);

  // 密码验证
  var pwd = this.document.querySelector('#pwd');
  var pwdReg = /^\w{6,16}$/;
  regexp(pwd, pwdReg);

  // 封装表单验证函数
  function regexp(ele, reg) {
    ele.addEventListener('blur', function () {
    if(reg.test(this.value)){
      this.nextElementSibling.className = 'success';
      this.nextElementSibling.innerHTML = '<i class="success_icon"></i>恭喜你输入正确';
    }else {
      this.nextElementSibling.className = 'error';
      this.nextElementSibling.innerHTML = '<i class="error_icon"></i>格式不正确，请重新输入';
    }
  });

  // 再次输入密码验证
  var surepwd = document.querySelector('#surepwd');
  surepwd.addEventListener('blur', function () {
    if(this.value == pwd.value){
      this.nextElementSibling.className = 'success';
      this.nextElementSibling.innerHTML = '<i class="success_icon"></i>恭喜你输入正确';
    }else {
      this.nextElementSibling.className = 'error';
      this.nextElementSibling.innerHTML = '<i class="error_icon"></i>两次密码输入不一致，请重新输入';
    }
  })
  }
})